﻿<Window x:Class="BingMapsWPFViewer.Main.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:avalonDock="http://avalondock.codeplex.com"
        xmlns:bing="clr-namespace:Microsoft.Maps.MapControl.WPF;assembly=Microsoft.Maps.MapControl.WPF"
        xmlns:local="clr-namespace:BingMapsWPFViewer.Main"
        xmlns:v="http://bingmapswpfviewer.codeplex.com/Views"
        xmlns:f="http://bingmapswpfviewer.codeplex.com/Framework"
        xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
        xmlns:prop="http://propertytools.codeplex.com"
        Title="Bing Maps Viewer"
        Icon="Images/layers.png"
        Height="600"
        Width="800">
    <Window.Resources>
        <BooleanToVisibilityConverter x:Key="bvc" />
    </Window.Resources>

    <Grid x:Name="LayoutRoot"
          Background="#FFF1EDED">
        <Grid.Resources>
            <v:LayerControlDataTemplateSelector x:Key="LayerControlDataTemplateSelector" />
        </Grid.Resources>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <!-- Bing API Key warning message -->
        <Border CornerRadius="5"
                Grid.Row="1"
                Visibility="{Binding IsKeyInvalid, Converter={StaticResource bvc}}"
                Background="#FFF9FFD4"
                Margin="2">
            <StackPanel Orientation="Horizontal">
                <Image Source="Images/warning.png"
                       Margin="10,0,0,0" />
                <TextBlock Text="Warning: Bing Maps API Key not set. "
                           FontSize="12"
                           Foreground="Black"
                           Margin="10" />
                <Button Style="{StaticResource LinkButton}"
                        Command="{Binding SetupCommand}"
                        CommandParameter="{Binding .[SetupView], Source={StaticResource ViewTypeLocator}}"
                        Content="Click here to setup your API key" />
            </StackPanel>
        </Border>

        <!-- Menu -->
        <Menu Grid.ColumnSpan="2"
              Grid.Row="0"
              Height="23"
              HorizontalAlignment="Stretch"
              Margin="0,0,0,0"
              Name="mnuMain"
              VerticalAlignment="Top">
            <MenuItem Header="File">
                <MenuItem Header="Quit"
                          x:Name="mnuQuit"
                          Command="{Binding QuitApplicationCommand}" />
            </MenuItem>
            <MenuItem Header="Edit" />
            <MenuItem Header="Layers">
                <MenuItem Header="New layer..."
                          x:Name="mnuNewLayer"
                          Command="{Binding LayerControlViewModel.NewLayerCommand}"
                          CommandParameter="{Binding .[NewLayerView], Source={StaticResource ViewTypeLocator}}">
                    <MenuItem.Icon>
                        <Image Source="/BingMapsWPFViewer.Main;component/Images/add.png"
                               Width="24"
                               Height="24" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="Edit layer..."
                          x:Name="mnuEditLayer"
                          Command="{Binding LayerControlViewModel.EditLayerCommand}"
                          CommandParameter="{Binding .[EditLayerView], Source={StaticResource ViewTypeLocator}}">
                    <MenuItem.Icon>
                        <Image Source="/BingMapsWPFViewer.Main;component/Images/edit2.png"
                               Width="16"
                               Height="16" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="Remove layer"
                          x:Name="mnuRemoveLayer"
                          Command="{Binding LayerControlViewModel.RemoveLayerCommand}">
                    <MenuItem.Icon>
                        <Image Source="/BingMapsWPFViewer.Main;component/Images/delete.png"
                               Width="16"
                               Height="16" />
                    </MenuItem.Icon>
                </MenuItem>
            </MenuItem>
            <MenuItem Header="Tools">
                <MenuItem Header="Get view info..."
                          Command="{Binding ViewInfoCommand}"
                          CommandParameter="{Binding .[MapInfoView], Source={StaticResource ViewTypeLocator}}" />
                <Separator />
                <MenuItem Header="Clear IE cache"
                          Command="{Binding ClearCacheCommand}" />
                <Separator />
                <MenuItem Header="Settings..."
                          Command="{Binding SetupCommand}"
                          CommandParameter="{Binding .[SetupView], Source={StaticResource ViewTypeLocator}}" />
            </MenuItem>
            <MenuItem Header="About"
                      Command="{Binding AboutCommand}" />
        </Menu>


        <!-- Dock -->
        <avalonDock:DockingManager x:Name="dockManager"
                                   Grid.Row="2">
            <avalonDock:LayoutRoot>
                <avalonDock:LayoutPanel Orientation="Horizontal">
                    <avalonDock:LayoutAnchorablePane DockWidth="250">
                        <avalonDock:LayoutAnchorable x:Name="layersLayout"
                                                     Title="Layer control"
                                                     CanHide="False"
                                                     CanClose="False">

                            <!-- Layer control -->

                            <Grid HorizontalAlignment="Stretch"
                                  VerticalAlignment="Stretch">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="50" />
                                    <RowDefinition Height="*" />
                                </Grid.RowDefinitions>

                                <StackPanel Grid.Row="0"
                                            HorizontalAlignment="Left"
                                            Orientation="Horizontal"
                                            DataContext="{Binding LayerControlViewModel}">
                                    <Button Name="btnAddLayer"
                                            Height="32"
                                            Width="32"
                                            Command="{Binding NewLayerCommand}"
                                            CommandParameter="{Binding .[NewLayerView], Source={StaticResource ViewTypeLocator}}"
                                            Background="{x:Null}">
                                        <Button.Content>
                                            <Image Source="/BingMapsWPFViewer.Main;component/Images/add.png"
                                                   Width="24"
                                                   Height="24" />
                                        </Button.Content>
                                    </Button>
                                    <Button Height="32"
                                            Width="32"
                                            Command="{Binding RemoveLayerCommand}"
                                            Margin="5"
                                            Background="{x:Null}">
                                        <Button.Content>
                                            <Image Source="/BingMapsWPFViewer.Main;component/Images/delete.png"
                                                   Width="24"
                                                   Height="24" />
                                        </Button.Content>
                                    </Button>
                                    <Button Name="btnEditLayer"
                                            Height="32"
                                            Width="32"
                                            Command="{Binding EditLayerCommand}"
                                            CommandParameter="{Binding .[EditLayerView], Source={StaticResource ViewTypeLocator}}"
                                            Background="{x:Null}">
                                        <Button.Content>
                                            <Image Source="/BingMapsWPFViewer.Main;component/Images/edit2.png"
                                                   Width="24"
                                                   Height="24" />
                                        </Button.Content>
                                    </Button>
                                    <Button Height="32"
                                            Width="32"
                                            Command="{Binding ZIndexUpCommand}"
                                            Margin="15,5,0,5"
                                            Background="{x:Null}">
                                        <Button.Content>
                                            <Image Source="/BingMapsWPFViewer.Main;component/Images/up.png"
                                                   Width="24"
                                                   Height="24" />
                                        </Button.Content>
                                    </Button>
                                    <Button Height="32"
                                            Width="32"
                                            Command="{Binding ZIndexDownCommand}"
                                            Margin="5"
                                            Background="{x:Null}">
                                        <Button.Content>
                                            <Image Source="/BingMapsWPFViewer.Main;component/Images/down.png"
                                                   Width="24"
                                                   Height="24" />
                                        </Button.Content>
                                    </Button>
                                </StackPanel>
                                <ListBox HorizontalAlignment="Stretch"
                                         Name="lstLayers"
                                         Grid.Row="1"
                                         VerticalAlignment="Stretch"
                                         DataContext="{Binding LayerControlViewModel}"
                                         ItemsSource="{Binding ZIndexView}"
                                         IsSynchronizedWithCurrentItem="True"
                                         ItemTemplateSelector="{StaticResource LayerControlDataTemplateSelector}">
                                    <i:Interaction.Triggers>
                                        <i:EventTrigger EventName="MouseDoubleClick">
                                            <i:InvokeCommandAction Command="{Binding EditLayerCommand}"
                                                                   CommandParameter="{Binding .[EditLayerView], Source={StaticResource ViewTypeLocator}}" />
                                        </i:EventTrigger>
                                    </i:Interaction.Triggers>
                                </ListBox>
                            </Grid>

                        </avalonDock:LayoutAnchorable>
                    </avalonDock:LayoutAnchorablePane>
                    <avalonDock:LayoutDocumentPane>
                        <avalonDock:LayoutDocument Title="Map"
                                                   CanClose="False"
                                                   CanFloat="False">
                            <Grid Grid.Column="1"
                                      Grid.Row="1">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="*"/>
                                </Grid.RowDefinitions>
                                <StackPanel Orientation="Horizontal" Grid.Row="0" Visibility="Collapsed">
                                    <Button Content="+" Width="20" Command="{Binding ZoomInCommand}"/>
                                    <Button Content="-" Width="20" Command="{Binding ZoomOutCommand}"/>
                                </StackPanel>
                                <!-- Map -->
                                <bing:Map x:Name="Map"
                                      Center="43.54121, 5.44683"
                                      Grid.Row="1"
                                      ZoomLevel="8"
                                      BorderBrush="Black"
                                      BorderThickness="1"
                                      Margin="5"
                                      DataContext="{Binding BingMapLayersViewModel}">
                                    <i:Interaction.Triggers>
                                        <f:EscKeyDownEventTrigger>
                                            <i:InvokeCommandAction Command="{Binding CancelDataQueryCommand}" />
                                        </f:EscKeyDownEventTrigger>
                                    </i:Interaction.Triggers>
                                    <bing:Map.Mode>
                                        <bing:MercatorMode />
                                    </bing:Map.Mode>
                                </bing:Map>
                            </Grid>
                        </avalonDock:LayoutDocument>
                    </avalonDock:LayoutDocumentPane>
                    <avalonDock:LayoutAnchorablePaneGroup DockWidth="200">

                        <avalonDock:LayoutAnchorablePane>
                            <avalonDock:LayoutAnchorable Title="Properties">
                                <!-- Properties content goes here -->

                                <ContentPresenter DataContext="{Binding BingMapLayersViewModel}">
                                    <ContentPresenter.ContentTemplate>
                                        <DataTemplate>
                                            <DataGrid ItemsSource="{Binding SelectedFeature.Attributes, Mode=OneWay}"
                                                      AutoGenerateColumns="False"
                                                      GridLinesVisibility="All"
                                                      HorizontalGridLinesBrush="#F0F0F0"
                                                      VerticalGridLinesBrush="#F0F0F0"
                                                      BorderThickness="0"
                                                      RowDetailsVisibilityMode="Visible"
                                                      HeadersVisibility="Column"
                                                      FrozenColumnCount="1"
                                                      HorizontalAlignment="Stretch"
                                                      VerticalAlignment="Stretch"
                                                      Margin="0"
                                                      IsSynchronizedWithCurrentItem="False"
                                                      CanUserReorderColumns="False"
                                                      CanUserSortColumns="False"
                                                      SelectionMode="Single"
                                                      SelectionUnit="CellOrRowHeader"
                                                      IsReadOnly="False">
                                                <DataGrid.Columns>
                                                    <DataGridTextColumn Width="SizeToCells"
                                                                        IsReadOnly="True"
                                                                        Binding="{Binding Key.FieldName}"></DataGridTextColumn>
                                                    <DataGridTextColumn Width="*"
                                                                        IsReadOnly="True"
                                                                        Binding="{Binding Value}"></DataGridTextColumn>
                                                </DataGrid.Columns>
                                            </DataGrid>
                                        </DataTemplate>
                                    </ContentPresenter.ContentTemplate>
                                </ContentPresenter>
                            </avalonDock:LayoutAnchorable>
                        </avalonDock:LayoutAnchorablePane>
                    </avalonDock:LayoutAnchorablePaneGroup>
                </avalonDock:LayoutPanel>


            </avalonDock:LayoutRoot>
        </avalonDock:DockingManager>


        <!-- Status bar -->
        <StatusBar Height="23"
                   Name="statusBar"
                   HorizontalAlignment="Stretch"
                   Grid.Row="3"
                   Grid.ColumnSpan="2"
                   VerticalAlignment="Bottom"
                   ItemsSource="{Binding StatusMessages}">
            <!--<StatusBarItem HorizontalAlignment="Right">
                <Separator />
            </StatusBarItem>
            <StatusBarItem HorizontalAlignment="Right">
                <TextBlock x:Name="lblZoomLevel"
                           Grid.Column="0"
                           HorizontalAlignment="Right"></TextBlock>
            </StatusBarItem>-->


        </StatusBar>

    </Grid>
</Window>
